window.onload = function () {
    // 获取查列表
    let tealist = document.getElementsByClassName("chaliebiao")[0];
    // console.log(tealist);
    $.ajax({
        type: "post",
        url: "/js/huixiantea",
        data: null,
        dataType: "json",
        success: function (data) {
            let s = "";
            for (let i = 0; i < data.length; i++) {
                // {id: 1, teaName: '茉莉花茶', teaType: '6', teaPrice: '223', teaImg: '茉莉花茶.webp'}
                id = data[i].id;
                teaName = data[i].teaName;
                teaType = data[i].teaType;
                teaPrice = data[i].teaPrice;
                teaImg = data[i].teaImg;
                s += `<div class="chaliebiao1">`
                s += `<img src="../img/${teaImg}" onclick="tiaozhuan(${id})">`
                s += `<div class="mingzi">${teaName}</div>`
                s += `<div class="jianbianxian"></div>`
                s += `<div class="jiage">￥${teaPrice}</div>`
                s += `<div class="jiantou"><div onclick="tiaozhuan(${id})">→</div></div>`
                s += `</div>`
            }
            tealist.innerHTML = s;
        }
    })
}

function chaleix(type) {
    if (type == 7) {
        location.reload()
    } else {
        let obj = {
            type: type
        }
        // 获取查列表
        let tealist = document.getElementsByClassName("chaliebiao")[0];
        $.ajax({
            type: "post",
            url: "/js/chaleix",
            data: JSON.stringify(obj),
            dataType: "json",
            success: function (data) {
                let s = "";
                tealist.innerHTML = s;
                for (let i = 0; i < data.length; i++) {
                    // {id: 1, teaName: '茉莉花茶', teaType: '6', teaPrice: '223', teaImg: '茉莉花茶.webp'}
                    id = data[i].id;
                    teaName = data[i].teaName;
                    teaType = data[i].teaType;
                    teaPrice = data[i].teaPrice;
                    teaImg = data[i].teaImg;
                    s += `<div class="chaliebiao1">`
                    s += `<img src="../img/${teaImg}" onclick="tiaozhuan(${id})">`
                    s += `<div class="mingzi">${teaName}</div>`
                    s += `<div class="jianbianxian"></div>`
                    s += `<div class="jiage">￥${teaPrice}</div>`
                    s += `<div class="jiantou"><div onclick="tiaozhuan(${id})">→</div></div>`
                    s += `</div>`
                }
                tealist.innerHTML = s;
            }
        })
    }
}

